package com.ly.web.controller.erp;

import com.ly.common.annotation.Log;
import com.ly.common.core.domain.AjaxResult;
import com.ly.common.enums.BusinessType;
import com.ly.common.utils.StringUtils;
import com.ly.heart.domain.KingFinanceReceiptRefundEntity;
import com.ly.heart.domain.dto.KingFinanceReceiptRefundDto;
import com.ly.heart.service.IKingFinanceReceiptRefundService;
import com.ly.heart.service.king.ReceiptRefundPushService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 收款退款单 前端控制器
 * </p>
 *
 * @author WuZH
 * @since 2024-08-04
 */
@Api ( value = "KingReceiptRefund", tags = "金蝶-收款退款单" )
@RestController
@RequestMapping ( "/heart/KingReceiptRefund" )
public class KingFinanceReceiptRefundController {

    @Resource
    private IKingFinanceReceiptRefundService iKingFinanceReceiptRefundService;
    @Resource
    private ReceiptRefundPushService receiptRefundPushService;

    @ApiOperation ("金蝶-收款退款单列表")
    @Log (title = "付款退款单列表")
    @GetMapping ( "list" )
    public AjaxResult queryList ( KingFinanceReceiptRefundEntity kingFinanceReceiptRefundEntity ) {
        AjaxResult ajaxResult = iKingFinanceReceiptRefundService.queryList ( kingFinanceReceiptRefundEntity );
        return ajaxResult;
    }

    @ApiOperation ("暂存金蝶-保存收款退款单")
    @PostMapping("draft")
    @Log ( title = "暂存收款退款单", businessType = BusinessType.INSERT )
    public AjaxResult draft ( @RequestBody KingFinanceReceiptRefundDto kingFinanceReceiptRefundDto ) {
        if ( StringUtils.isNotBlank ( kingFinanceReceiptRefundDto.getKingFinanceReceiptRefundEntity ().getId () ) ) {
            return iKingFinanceReceiptRefundService.updateSingle ( kingFinanceReceiptRefundDto );
        }
        return iKingFinanceReceiptRefundService.draft ( kingFinanceReceiptRefundDto );
    }

    @ApiOperation ("提交金蝶-保存收款退款单")
    @PostMapping("submit")
    @Log ( title = "提交收款退款单", businessType = BusinessType.INSERT )
    public AjaxResult submit ( @RequestBody KingFinanceReceiptRefundEntity kingFinanceReceiptRefundEntity ) {
        return iKingFinanceReceiptRefundService.submit ( kingFinanceReceiptRefundEntity );
    }

    @PreAuthorize ( "@ss.hasPermi('heart:KingReceiptRefund:query')" )
    @GetMapping ( value = "/{id}" )
    @ApiOperation ( "获取金蝶-财务-付款单详细信息" )
    public AjaxResult getInfo ( @PathVariable ( "id" ) String id ) {
        return AjaxResult.success ( iKingFinanceReceiptRefundService.querySingle ( id ) );
    }

    //@PreAuthorize ( "@ss.hasPermi('heart:KingReceiptRefund:edit')" )
    @Log ( title = "修改收款退款单", businessType = BusinessType.UPDATE )
    @PutMapping
    @ApiOperation ( "修改收款退款单" )
    public AjaxResult edit ( @RequestBody KingFinanceReceiptRefundDto kingFinanceReceiptRefundDto ) {
        return iKingFinanceReceiptRefundService.updateSingle ( kingFinanceReceiptRefundDto );
    }

    @Log ( title = "推送收款退款单到金蝶" )
    @GetMapping ( "/send/{id}" )
    @ApiOperation ( "推送收款退款单到金蝶" )
    public AjaxResult send ( @PathVariable String id ) {
        receiptRefundPushService.push ( id );
        return AjaxResult.success ();
    }

}
